package com.whut.common;

import lombok.Data;

import java.io.Serializable;

@Data
public class BaseResponse implements Serializable {

    private static final long serialVersionUID = 864905203816030930L;

    private String msg = "OK";

    private int code = ResponseCode.CODE_OK;

    private Object data = "";

    @Override
    public String toString() {
        return "BaseResponse [msg=" + msg + ", code=" + code
                + ", data=" + data + "]";
    }

    public BaseResponse(int code) {
        this.code = code;
        switch (code) {
            case 404:
                this.msg = "接口地址不正确";
                break;
            case 405:
                this.msg = "请求方法不支持,request method not allowed";
                break;
            case 500:
                this.msg = "服务内部错误";
                break;
            case 1001:
                this.msg = "暂无数据";
                break;
            case 1002:
                this.msg = "参数错误";
                break;
            default:
                break;
        }
    }

    public BaseResponse(String msg, int code, Object data) {
        super();
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    /**
     * 成功
     */
    public BaseResponse() {
        super();
        this.msg = ResponseCode.CODE_OK_MSG;
        this.code = ResponseCode.CODE_OK;
        this.data = "";
    }

    /**
     * 服务异常
     */
    public BaseResponse(String msg) {
        super();
        this.msg = msg;
        this.code = ResponseCode.CODE_SYSTEM_ERROR;
        this.data = "";
    }


    /**
     * 成功
     *
     * @param data
     */
    public BaseResponse(Object data) { //正确
        super();
        this.msg = ResponseCode.CODE_OK_MSG;
        this.code = ResponseCode.CODE_OK;
        this.data = data;
    }

}
